#pragma once

#include <vector>
#include <istream>
#include <string>
#include <stdexcept>
#include <algorithm>
#include "Comparators.h"
#include "Sorter.h"

template<>
class Sorter<std::string> {
public:
	void sort(std::istream& inputStream, CompareMode compareMode, std::vector<std::string>& results) {
		if( !inputStream.good() ) {
			throw std::invalid_argument("Input stream is bad");
		}

		readData(inputStream, results);

		switch( compareMode ) {
		case ACSENDING:
			std::sort(results.begin(), results.end(), Comparator<std::string>::compareAscend);
			break;
		case DESCENDING:
			std::sort(results.begin(), results.end(), Comparator<std::string>::compareDescend);
			break;
		case RANDOM:
			std::random_shuffle(results.begin(), results.end());
			break;
		default:
			throw std::invalid_argument("Unknown sort mode");
			break;
		}
	}

	void readData(std::istream& inputStream, std::vector<std::string>& results) {
		while( inputStream.good() ) {
			std::string readData;
			getline(inputStream, readData);
			results.push_back( readData );
		}
	}
};